<?php
declare (strict_types = 1);
/**
 * 频道管理
 */
namespace app\common\admin;

use app\common\facade\model\ChannelInfoModel;

class Channel extends BaseAdmin
{
    /**
     * 频道列表
     * @param array $param
     * @return mixed
     */
    public function channelList($param = []){
        $where = [];
        if (isset($param['channel_name']) && !empty($param['channel_name'])) $where[] = ['channel_name', 'like', "%{$param['channel_name']}%"];
        $list = ChannelInfoModel::channelList($where,(integer)$param['offset'],(integer)$param['pagesize']);
        return $list;
    }

    /**
     * 频道详情
     * @param array $param
     * @return mixed
     */
    public function channelInfo($param = []){
        $where = [];
        if (isset($param['id']) && !empty($param['id'])) $where[] = ['id', '=', "{$param['id']}"];
        return ChannelInfoModel::info($where);;
    }

    /**
     * 添加频道
     * @param array $param
     */
    public function channelAdd($param = []){
        if(isset($param['id'])):
            unset($param['id']);
        endif;
        ChannelInfoModel::addEditSave($param);
        return true;
    }

    /**
     * 编辑频道
     * @param array $param
     */
    public function channelEdit($param = []){
        $where = [];
        if (isset($param['id']) && !empty($param['id'])) $where[] = ['id', '=', "{$param['id']}"];
        $param['up_time']  = date('Y-m-d H:i:s',time());
        ChannelInfoModel::dateUpdate($param);
        return true;
    }

    /**
     * 频道删除
     * @param array $param
     * @return mixed
     */
    public function channelDel($param = []){
        if(empty($param['id'])) exception('删除失败！');
        $where = [['id', '=', $param['id']]];
        return ChannelInfoModel::deleteData($where);;
    }


}